home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-04 | 4.7 KB | 208 lines | [TEXT/CWIE] |
- // MADE - Macintosh Application Development Essentials
- // ---------------------------------------------------
-
- // (c) Gideon Greenspan, Sig Software - June 1997 - http://www.kagi.com/gdg/
-
- // These files can only be used for experimental standalone purposes. To obtain
- // fully commented code, and licenses for standalone, shareware, internal and
- // commercial usage, run the enclosed Register application.
-
- // Essential Menus.h
- //
- // Menu bar handling, item enabling, Drag Manager and cursor routines.
- //
- // Version 1.0.0 - 10th November 1996
- // Version 1.0.1 - 4th June 1997
- // Fixed resetting port in DragTrackHandler
-
- #include "Essential Headers.h"
- #include "Essential Prototypes.h"
-
- #if Use_Drag_Manager
-
- // NOTE : UPP (Universal Procedure Pointers) are used to ensure compatiblity under 680x0,
- // PowerPC, and who knows what other future compilers.
-
- #include <Drag.h>
-
- // No support is provided here for data send procedures, but these can be added if needed
-
- pascal OSErr DragTrackHandler(DragTrackingMessage, WindowPtr, void *, DragReference);
- pascal OSErr DragReceivHandler(WindowPtr, void*, DragReference);
- DragTrackingHandlerUPP DragTrackUPP;
- DragReceiveHandlerUPP DragReceivUPP;
-
- #endif
-
- // Menu item switching is based on the fact that the upper 16 bits of the value returned by
- // the system are the menu's ID and the lower 16 bits are the item number chosen in that menu.
- // Just remember these are IDs defined within the MENU resource, not the resource ID itself.
-
- enum {
- AppleStart=128*65536,
- AppleAbout,
- AppleSep1,
- AppleItems,
- AppleEnd=128*65536+65535
- };
-
- Error InitMenuBar()
- {
- Error error=0;
- Handle theMenuBar;
- MenuHandle theAppleMenu;
-
- theMenuBar=GetNewMBar(128);
- error=TestResError(theMenuBar);
- _i(error)
-
- SetMenuBar(theMenuBar);
-
- theAppleMenu=GetMHandle(128);
- AddResMenu(theAppleMenu, 'DRVR');
-
- DrawMenuBar();
-
- _e
- return error;
- }
-
- void SelectMenuItem(long selection)
- {
- Str255 menuItemName;
-
- if (selection>=AppleItems && selection<=AppleEnd) {
- GetItem(GetMHandle(128), selection-AppleStart, menuItemName);
- OpenDeskAcc(menuItemName);
- } else
- MyPerformMenu(selection);
-
- HiliteMenu(0);
- }
-
- void EnableMenuItem(short menuID, short menuItem, Boolean enable)
- {
- MenuHandle menuHandle;
-
- menuHandle=GetMHandle(menuID);
-
- if (enable) EnableItem(menuHandle, menuItem);
- else DisableItem(menuHandle, menuItem);
- }
-
- void ShowResCursor(short cursorID)
- {
- CursPtr theCursor;
-
- theCursor=*GetCursor(cursorID);
- SetCursor(theCursor);
- }
-
- #if Use_Drag_Manager
-
- // In this model, a single Track and Receive handler is used for all drags. You can make
- // separate ones for each window. Also, the refCon parameter is left at zero here.
-
- Error InitDragManager()
- {
- Error error=0;
-
- DragTrackUPP=NewDragTrackingHandlerProc(DragTrackHandler);
- error=InstallTrackingHandler(DragTrackUPP, 0, 0);
- TestError(error);
- _i(error);
-
- DragReceivUPP=NewDragReceiveHandlerProc(DragReceivHandler);
- error=InstallReceiveHandler(DragReceivUPP, 0, 0);
- TestError(error);
-
- _e
- return error;
- }
-
- pascal OSErr DragTrackHandler(DragTrackingMessage message, WindowPtr inWindow,
- void* refCon, DragReference dragRef)
- {
- Point localPoint;
- DragAttributes attributes;
- RgnHandle region;
- GrafPtr oldPort;
- Error error=0;
-
- error=GetDragAttributes(dragRef, &attributes);
- _i(error)
- GetPort(&oldPort);
-
- switch (message) {
-
- case dragTrackingInWindow:
- if (attributes&dragHasLeftSenderWindow) {
-
- error=GetDragMouse(dragRef, &localPoint, 0);
- _i(error)
-
- SetPort(inWindow);
- GlobalToLocal(&localPoint);
-
- region=MyGetDragRegion(inWindow, localPoint, dragRef);
-
- if (region) {
- ShowDragHilite(dragRef, region, true);
- DisposeRgn(region);
-
- } else
- HideDragHilite(dragRef);
-
- }
- break;
-
- case dragTrackingLeaveWindow: case dragTrackingLeaveHandler:
- SetPort(inWindow);
- HideDragHilite(dragRef);
- break;
-
- }
- SetPort(oldPort);
-
- _e
- return error;
- }
-
- pascal OSErr DragReceivHandler(WindowPtr inWindow, void* refCon, DragReference dragRef)
- {
- Error error=0;
- WindowPtr oldPort;
- Point localPoint;
-
- error=GetDragMouse(dragRef, &localPoint, 0);
- _i(error)
-
- GetPort(&oldPort);
- SetPort(inWindow);
- GlobalToLocal(&localPoint);
- SetPort(oldPort);
-
- MyReceiveDrag(inWindow, localPoint, dragRef);
-
- _e
- return error;
- }
-
- void CreateDragRegion(RgnHandle region)
- {
- RgnHandle subtractRgn;
- Point dummyPoint;
-
- subtractRgn=NewRgn();
- CopyRgn(region, subtractRgn);
- InsetRgn(subtractRgn, 1, 1);
- DiffRgn(region, subtractRgn, region);
- DisposeRgn(subtractRgn);
-
- dummyPoint.h=dummyPoint.v=0;
- LocalToGlobal(&dummyPoint);
- OffsetRgn(region, dummyPoint.h, dummyPoint.v);
- }
-
- #endif
-